<?php
class convention_annex_mdl extends CI_Model
{




     public function get_numero_annex()
	{


	$query = $this->db->query("SELECT
convention_annex.numero
FROM
convention_annex
ORDER BY
convention_annex.numero DESC
LIMIT 0, 1

 ");
	
return $query->result();

	}
	
	 public function ajout_annex($id_convention,$numero_annex,$tva)
	{

$today = getdate();
			$date=$today['year'].'-'.$today['mon'].'-'.$today['mday'];
			
	$query = $this->db->query("INSERT INTO `convention_annex` (`id_convetion`,`numero`,`date`,`tva`) VALUES ('$id_convention','$numero_annex','$date','$tva')
 ");
 
 $query1 = $this->db->query("SELECT
convention_annex.id_convention_annex
FROM
convention_annex
ORDER BY
convention_annex.id_convention_annex DESC
LIMIT 0, 1

 ");
	
return $query1->result();

	}

     public function supprime_annex($id_annex)
	{
			
	$query = $this->db->query("DELETE FROM `convention_annex` WHERE (`id_convention_annex`='$id_annex')
 ");


	}

     public function get_annex_detaille($id_annex)
	{


	
 $query1 = $this->db->query("SELECT
conventions.numero AS numero_convention,
convention_annex.numero AS numero_annex,
convention_annex.id_convention_annex,
convention_annex.date,
produit_annex_conv.pu,
produit_annex_conv.quantite,
convention_annex.tva,
produits.dessignation,
fournisseurs.nom,
fournisseurs.id_fournisseur,
articles.nom AS article,
articles.`code`,
produit_annex_conv.id_produit,
convention_annex.id_convetion,
conventions.montant AS montant_convention,
conventions.annee,
convention_annex.montant AS montant
FROM
conventions
INNER JOIN convention_annex ON convention_annex.id_convetion = conventions.id_convetion
LEFT JOIN produit_annex_conv ON produit_annex_conv.id_annex_conv_fk = convention_annex.id_convention_annex
LEFT JOIN produits ON produit_annex_conv.id_produit_fk = produits.id_produit
INNER JOIN fournisseurs ON conventions.id_fourn_fk = fournisseurs.id_fournisseur
INNER JOIN articles ON conventions.id_article_fk = articles.id_article
WHERE
convention_annex.id_convention_annex = $id_annex

 ");
	
return $query1->result();

	}

     public function ajout_produit_annex_conv($id_produit,$pu,$quantite,$id_annex_conv)
	{

$this->load->library('session');
     $tva=$this->session->userdata('tva');
	 
	$query = $this->db->query("INSERT INTO `produit_annex_conv` (`id_produit_fk`, `pu`, `quantite`, `id_annex_conv_fk`, `tva`) VALUES ('$id_produit', '$pu', '$quantite', '$id_annex_conv','$tva')
 ");
 

	}

      public function set_montant_annex($id,$montant)
	{
 
	$query = $this->db->query("UPDATE `convention_annex` SET  `montant`='$montant' WHERE (`id_convention_annex`='$id')
 ");
 

	}

   
     
}


?>